<?php

namespace App\Models;

use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;

class ModConf extends Model
{
    protected $table ='mod_conf';


    public static function ClearConfigStr(int $serverType,string $str,bool $arr=false) {
        $eol="\n";
//        if ($serverType===1)
//            $eol="\r\n";
        if(strpos($str,"\r\n") !== false){
            $eol="\r\n";
        }

        $list=explode($eol,$str);
        $lines=[];
        foreach ($list as $line){
            $first=substr($line,0,1);
            if ($line!=='' && $first!=='#' && $first!=='[')
                array_push($lines,$line);
        }
        if ($arr) return $lines;
        $res=implode($eol,$lines);
        return $res;
    }

    public static function ArrToKey(array $arrNumber){
        $arrConf=[];
        foreach ($arrNumber as $item) {
            if ( trim($item)!=''){
                $kv = explode('=', $item);
                if (sizeof($kv)==2){
                    $k = trim($kv[0]);
                    $v = trim($kv[1]);
                    $arrConf[$k] = ['value' => $v];
                }else{
                    Log::warning('配置解析错误：'.$item);
                }
            }
        }
        return $arrConf;
    }
    public static function ArrToNumber(array $arrkey){

    }

    public static function ConfigMerge(){

    }
}
